<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/head.jsp"%>
</head>
<body>
	<div align="center" style="padding-top: 10px;">
		<img id="img" src="" style="width: 350xp; height: 350px;">
	</div>
	<div align="center" style="padding-top: 15px;">
		<button class="layui-btn" onclick="reset()">初始化头像</button>
		<button class="layui-btn" id="confirm">确认修改</button>
	</div>

	<script type="text/javascript">
	
		var account = '<%=request.getParameter("account")%>'
		// 头像回显
		ajax('/WriterServlet', 'json', {
			account : account,
			action : "getModel"
		}, function(data) {
			$('img').attr('src', "/image/" + data.image)
		})
		
		
		// 选择头像
		uploadImage('img', 'confirm', '/WriterUpload', function(obj) {
			// 选择头像
			obj.preview(function(index, file, result) {
				$('img').attr('src', result)
			})
		}, function(res) {
			// 上传头像完毕
			ajax('/WriterServlet', 'text', {
				account : account,
				image : res.image[0],
				action:'updata'
			},function(res){
				if(res == 'success'){
					layer.msg('修改成功',{time:1000},frameClose)
				}else{
					layer.msg('修改失败',{time:1000})
				}
			})
		})
			
		function reset(){
			ajax('/WriterServlet', 'text', {
				account : account,
				image : 'base.jfif',
				action:'updata'
			}, function(res) {
				if(res == 'success'){
					layer.msg('初始化成功',{time:1000},frameClose)
				}else{
					layer.msg('初始化失败',{time:1000})
				}
			})
		}
		
	</script>
</body>
</html>